home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / record11.zip / RECORD11.ASM < prev    next >
Assembly Source File  |  1988-07-31  |  23KB  |  795 lines

  1.         Page 60,132
  2. ;----------------------------------------------------------------------
  3. ; RECORDER.ASM - A resident program which counts file operations.
  4. ; Run it once to install and initialize it.  Run it again later to
  5. ; view a list of files which have been accessed.  The table
  6. ; shows how many disk accesses have been made while reading and
  7. ; writing to the file.
  8. ;
  9. ; SYNTAX:   RECORDER  [n] [/R]
  10. ; USE   n to specify the maximum number of files (default=200)
  11. ; Use  /R to reset the file table.
  12. ;Toad Hall Tweak, Jul 88
  13. ; - tightened code a little
  14. ; - no functional changes
  15. ;David Kirschbaum
  16. ;Toad Hall
  17. ;kirsch@braggvax.ARPA
  18. ;----------------------------------------------------------------------
  19.  
  20. CSEG    SEGMENT para public 'CODE'
  21.     ASSUME    CS:CSEG,DS:CSEG, ES:CSEG
  22.  
  23.     ORG    100H    ;Beginning for .COM programs
  24.  
  25. Start    proc    near
  26.     JMP    Initialize        ;Initialization code is at end
  27.  
  28. ;-----------------------------------------------------------------------
  29. ; Data area used by this program
  30. ;-----------------------------------------------------------------------
  31. COPYRIGHT    DB    'RECORDER 1.1',0DH,0AH,'$'
  32. ;        db    ' (c) 1988 Ziff Communications Co.'
  33. ;PROGRAMMER    DB    13,10,'PC Magazine ',254,' Tom Kihlken$',1AH
  34.  
  35. full_mess    DB    '*Table is saturated*$'
  36. oldint21    DD    ?    ;Old DOS function interrupt vector
  37. oldint13    DD    ?    ;Old BIOS disk I/O interrupt vector
  38. num_files    DW    200    ;Default size of the table
  39. file_table_end    DW    ?
  40. last_file    DW    ?
  41. last_handle    DW    ?
  42.  
  43. current_file    DB    11 DUP (?)
  44. current_handle    DW    ?
  45. function_id    DW    ?
  46. busy_flag    DB    0
  47. bios_IO_count    DW    0    ;Counts disk accesses made by BIOS
  48.  
  49. HANDLE_TABLE    EQU    OFFSET header    ;TH was Initialize
  50. FILE_TABLE    EQU    HANDLE_TABLE + NUM_HANDLES * 4
  51. NUM_HANDLES    EQU    30
  52. ENTRY_SIZE    EQU    20
  53. Start    endp
  54.  
  55. ;-----------------------------------------------------------------------
  56. ; Interrupt 13 (Diskette I/O) This routine counts disk sector accesses.
  57. ;-----------------------------------------------------------------------
  58. NewInt13    PROC    FAR
  59.     ASSUME    DS:NOTHING, ES:NOTHING
  60.     CMP    AH,2            ;Is function lower than 2?
  61.     JB    Dont_Count        ;If yes, then ignore it
  62.     CMP    AH,4            ;Is function higher than 4?
  63.     JA    Dont_Count        ;If yes, then ignore it
  64.     INC    CS:bios_IO_count    ;Add sectors count to total
  65. Dont_Count:
  66.     JMP    CS:oldint13        ;Continue with disk interrupt
  67. NewInt13    ENDP
  68.  
  69. ;-----------------------------------------------------------------------
  70. ; Interrupt 21 (DOS functions)  This routine counts file accesses.
  71. ;-----------------------------------------------------------------------
  72. NewInt21    PROC    FAR
  73.     ASSUME    DS:NOTHING, ES:NOTHING
  74.  
  75.     PUSHF                ;Save callers flags
  76.     STI                ;Get interrupts back on
  77.     CMP    CS:busy_flag,0        ;Are we busy now?
  78.     JNE    Old_Dos            ;If busy, just pass it to DOS
  79.     CMP    AH,4BH            ;Is it the EXEC function?
  80.     JE    Exec            ;Handle EXEC specially
  81.     CMP    AH,0EH            ;Is it below 0EH?
  82.     JBE    Old_Dos            ;If yes, ignore it
  83.     CMP    AH,31H            ;Is it TSR function?
  84.     JE    Old_Dos            ;Dont intercept this call
  85.     CMP    AH,45H            ;Is it above 45H?
  86.     JB    Intercept_It        ;If yes, then ignore it
  87. Old_Dos:
  88.     POPF                ;Recover callers flags
  89.     CLI
  90.     JMP    CS:oldint21        ;Allow interrupt to proceed
  91.  
  92. Exec:
  93.     PUSH    AX            ;Save these registers
  94.     PUSH    BX
  95.     PUSH    CX
  96.     PUSH    SI
  97.     PUSH    DI
  98.     PUSH    DS
  99.     PUSH    ES
  100.     MOV    CS:busy_flag,1        ;Set the busy flag
  101.     MOV    SI,OFFSET Parse_String    ;Point to parse routine
  102.     CALL    Enter_Filename        ;Search file table for the file
  103.     JC    Exec_Continue
  104.      INC    WORD PTR [SI+12]    ;TH
  105.      INC    WORD PTR [SI+12]    ;TH
  106. Exec_Continue:
  107.     MOV    CS:busy_flag,0        ;Not busy any more
  108.     POP    ES            ;Restore the registers
  109.     POP    DS
  110.     POP    DI
  111.     POP    SI
  112.     POP    CX
  113.     POP    BX
  114.     POP    AX
  115.     JMP    Old_Dos
  116.  
  117. Intercept_It:
  118.     MOV    busy_flag,1        ;Ignore any other calls
  119.     MOV    function_id,AX        ;Save the function ident.,
  120.     MOV    bios_IO_count,0
  121.     CLI
  122.     CALL    CS:oldint21        ;Do the DOS function
  123.     STI                ;Reenable interrupts
  124.     PUSHF                ;Save DOS result flags
  125.     PUSH    AX            ;Save these registers
  126.     PUSH    BX
  127.     PUSH    CX
  128.     PUSH    DX
  129.     PUSH    SI
  130.     PUSH    DI
  131.     PUSH    DS
  132.     PUSH    ES
  133.     JNC    Check_Function        ;If no error, continue
  134.      JMP    Pop_Ret            ;Otherwise just return
  135.  
  136. Check_Function:
  137.     MOV    CX,function_id
  138.     SUB    CH,0FH        ;Is it 0Fh?
  139.     JZ    Read_FCB
  140.     DEC    CH        ;Is it 10h?
  141.     JZ    Write_FCB
  142.     SUB    CH,4        ;Is it 14h?
  143.     JZ    Read_FCB
  144.     DEC    CH        ;Is it 15h?
  145.     JZ    Write_FCB
  146.     DEC    CH        ;Is it 16h?
  147.     JZ    Read_FCB
  148.     SUB    CH,0BH        ;Is it 21h?
  149.     JZ    Read_FCB
  150.     DEC    CH        ;Is it 22h?
  151.     JZ    Write_FCB
  152.     DEC    CH        ;Is it 23h?
  153.     JZ    Read_FCB
  154.     SUB    CH,4        ;Is it 27h?
  155.     JZ    Read_FCB
  156.     DEC    CH        ;Is it 28h?
  157.     JZ    Write_FCB
  158.     JMP    SHORT Not_FCB_Functn
  159.  
  160. Read_FCB:
  161.     MOV    BX,14            ;Index for the read column
  162.     JMP    SHORT Inc_FCB_Count
  163.  
  164. Write_FCB:
  165.     MOV    BX,16            ;Index for the write column
  166. Inc_FCB_Count:
  167.     MOV    SI,OFFSET Parse_FCB
  168.     CALL    Enter_Filename        ;Search file table for the file
  169.     JC    Jump_Pop_Ret        ;Quit if file not in table
  170.     MOV    AX,bios_IO_count    ;This many disk operations made
  171.     ADD    CS:[SI][BX],AX        ;Add it to the indexed column
  172.     ADD    CS:[SI+12],AX        ;Add it to the total
  173.     JMP    Pop_Ret
  174.  
  175. ; If it was not a FCB function, see if it was handle I/O
  176.  
  177. Not_FCB_Functn:
  178.     SUB    CH,14H        ;Is it 3Ch?
  179.     JE    New_Handle
  180.     DEC    CH        ;Is it 3Dh?
  181.     JE    New_Handle
  182.     DEC    CH        ;Is it 3Eh?
  183.     JE    Write_Handle
  184.     DEC    CH        ;Is it 3Fh?
  185.     JE    Read_Handle
  186.     DEC    CH        ;Is it 40h?
  187.     JE    Write_Handle
  188.     SUB    CH,2        ;Is it 42h?
  189.     JE    Read_Handle
  190.     SUB    CH,2        ;Is it 44h?
  191.     JE    IO_Control
  192.     JMP    Pop_Ret
  193.  
  194. New_Handle:
  195.     CMP    AX,5            ;Is it a standard handle?
  196.     JGE    Good_Handle        ;If not, then record it
  197. Jump_Pop_Ret:
  198.     JMP    Pop_Ret            ;Jump to the return
  199.  
  200. Read_Handle:
  201.     MOV    CX,14            ;Index for the read column
  202.     JMP    SHORT Inc_Dev_Count
  203.  
  204. IO_Control:
  205.     CMP    CL,2            ;Is it a read request?
  206.     JE    Read_Handle        ;Treat it as a read
  207.     CMP    CL,3            ;Is it a write request?
  208.     JNE    Jump_Pop_Ret        ;If not read or write, ignore it
  209. Write_Handle:
  210.     MOV    CX,16            ;Index for the write column
  211. Inc_Dev_Count:
  212.     CMP    BX,5            ;Is it a standard handle?
  213.     JB    Jump_Pop_Ret        ;If it is, then ignore it
  214.     PUSH    CX            ;Put index on the stack
  215.  
  216. ; Now search the handle table for the handle in BX.
  217.  
  218.     CALL    Add_PSP            ;Add in the current PSP segment
  219.     MOV    DI,HANDLE_TABLE        ;Point to the handle table
  220.     MOV    CX,NUM_HANDLES        ;Search the entire table
  221. Handle_Loop:
  222.     CMP    BX,CS:[DI]        ;Is it a match?
  223.     JE    Handle_Match        ;If it is, we've found it
  224.     ADD    DI,4            ;If not, look at next entry
  225.     LOOP    Handle_Loop
  226.     POP    BX            ;Restore the stack
  227.     JMP    SHORT Pop_Ret        ;Return if handle was not found
  228.  
  229. ; If the handle is being closed, then the entry is deleted.
  230.  
  231. Handle_Match:
  232.     CMP    BYTE PTR function_id+1,3EH ;Closing this file?
  233.     JNE    Not_Close
  234.      MOV    WORD PTR CS:[DI],0
  235. Not_Close:
  236.     MOV    DI,CS:[DI+2]        ;Get pointer to file table entry
  237.     POP    BX            ;Get the index back
  238.     MOV    AX,bios_IO_count    ;Get the sector count
  239.     ADD    CS:[DI][BX],AX        ;Add it to selected column
  240.     ADD    CS:[DI+12],AX        ;And also to the total column
  241.     JMP    SHORT Pop_Ret
  242.  
  243. Good_Handle:
  244.     MOV    current_handle,AX    ;Save the handle
  245.     MOV    SI,OFFSET Parse_String    ;Point to parse routine
  246.     CALL    Enter_Filename        ;Add the file to the table
  247.     JC    Jump_Pop_Ret        ;If table is full, return
  248.     MOV    AX,bios_IO_count    ;Get number of sectors
  249.     add    [SI+12],ax        ;TH Add to the total column
  250.     add    [SI+14],ax        ;TH Add to the read column
  251.  
  252. ; Now enter this new handle to the handle table
  253.  
  254.     MOV    DI,last_handle        ;Get location of last entry
  255.     ADD    DI,4            ;Advance it one position
  256.     CMP    DI,HANDLE_TABLE+NUM_HANDLES*4
  257.     JNE    Keep_Going
  258.      MOV    DI,HANDLE_TABLE
  259. Keep_Going:
  260.     MOV    last_handle,DI        ;Now this is the last handle
  261.     MOV    BX,current_handle    ;Get handle back
  262.     CALL    Add_PSP            ;Add in the current PSP segment
  263.     MOV    CS:[DI],BX        ;Store the handle
  264.     MOV    CS:[DI+2],SI        ;Store location in file table
  265. Pop_Ret:
  266.     MOV    CS:busy_flag,0        ;Not busy any more
  267.     POP    ES            ;Restore all registers
  268.     POP    DS
  269.     POP    DI
  270.     POP    SI
  271.     POP    DX
  272.     POP    CX
  273.     POP    BX
  274.     POP    AX
  275.     POPF                ;Recover DOS result flags
  276.     STI                ;Return with interrupts on
  277.     RET    2            ;Return with these flags
  278. NewInt21    ENDP
  279.  
  280. ;-----------------------------------------------------------------------
  281. ; Enter_Filename adds the file at DS:DX to the table.
  282. ; It returns with DS:SI pointing to the entry.  If CF=1, then the name
  283. ; was not in the table and no more entries could be added.
  284. ;----------------------------------------------------------------------